/*
 * CodeSaveCommand.java
 *
 * Created on 2006년 3월 29일 (수), 오후 4:11
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.qbooks.store.help;

import java.util.*;




import javax.servlet.*;
import javax.servlet.http.*;

import org.json.simple.JSONObject;

import com.zll.framework.model.HashBox;
import com.zll.framework.model.HashList;
import com.zll.framework.servlet.Command;
import com.qbooks.common.CommonDAO;
import com.qbooks.common.CommonUtil;





/**
 *
 * @author eastar
 */
public class SellerLoginCommand implements Command
{

    public String execute(HttpServletRequest  request, HttpServletResponse response)
    throws Exception
    {
    	JSONObject json = new JSONObject();

		HashBox box = new HashBox(request);

		HelpDAO dao 		= new HelpDAO();

		
		HashList list = dao.selectSellerList(box.getParam());

		if (list.size() == 1) {
			String seller_pw = list.get("seller_pw", 0);
			if (box.get("seller_pw").equals(seller_pw)) {
				json.put("result", true);
				json.put("nextUrl", "/home/help/sellerSalesList.jsp");

				HttpSession session = request.getSession();
				session.setAttribute("session.user_id", list.get("seller_id",0));
				session.setAttribute("session.user_name", list.get("seller_name",0));
				session.setAttribute("session.user_auth", list.get("auth_code",0));
				session.setAttribute("session.auth_name", list.get("auth_name",0));

			} else {
				json.put("result", false);
				json.put("message", "비밀번호가 일치하지 않습니다.");
			}

		} else {
			json.put("result", false);
			json.put("message", "존재하지 않는 회원입니다");
		}

		request.setAttribute("jsonData", json.toString());


    	return "/common/json_view.jsp";
    }
}
